import enum
import json
from typing import List

from sqlalchemy.dialects.postgresql import UUID
from extensions.ext_database import db


class ReadStatus(str, enum.Enum):
    READ = 'read'
    UNREAD = 'unread'


class SerpResult(db.Model):
    __tablename__ = 'serp_results'
    __table_args__ = (
        db.PrimaryKeyConstraint('id', name='account_pkey'),
    )

    id = db.Column(UUID, server_default=db.text('uuid_generate_v4()'))
    title = db.Column(db.String(255), nullable=False)
    link = db.Column(db.String(255), nullable=False)
    source = db.Column(db.String(255), nullable=True)
    date = db.Column(db.String(255), nullable=True)
    snippet = db.Column(db.String(255), nullable=True)
    status = db.Column(db.String(16), nullable=False, server_default=db.text("'unread'::character varying"))
    created_at = db.Column(db.DateTime, nullable=False, server_default=db.text('CURRENT_TIMESTAMP(0)'))

    def get_status(self) -> ReadStatus:
        status_str = self.status
        return ReadStatus(status_str)


